/*
 * Copyright 2005 ShenYang Boyasi Co. Ltd.
 * All right reserved.
 */

package com.wm.comm;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * @author SunFlower
 * 
 * @version v1.0 , 2007-4-11
 * 
 * �����֤ͼƬ
 */
public class RandomImageServlet extends HttpServlet {
	private static final long serialVersionUID = 6874299306819965344L;
	public final static String RANDOM_LOGIN_KEY = "RANDOM_LOGIN_KEY";

	 public void init() throws ServletException {
	  System.setProperty("java.awt.headless","true");
	 }

	    public static String getRandomLoginKey(HttpServletRequest req) {
	        return (String)req.getSession().getAttribute(RANDOM_LOGIN_KEY);
	    }

	    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
	    {
	        HttpSession ssn = req.getSession();
	        if(ssn!=null) {
	            String randomString = RandomImageGenerator.random();//�������
	            ssn.setAttribute(RANDOM_LOGIN_KEY,randomString);//�����ӷŵ�session����
	            res.setContentType("image/jpeg");//����ͼ����ɸ�ʽ
	            RandomImageGenerator.render(randomString,res.getOutputStream());//���ҳ��
	        }
	    }
}
